{% extends "templates/main_template.html.j2" %}

{% import "macros/issues_table.html.j2" as ISSUES_TABLE %}
{% import "macros/date_range_picker.html.j2" as DATE_RANGE_PICKER %}

{% block title %}Отчёт · Farado{% endblock %}

{% set active_menu = 'report' %}


{#----------------------------------------------------------------------------#}
{% block styles %}
  {{ ISSUES_TABLE.STYLES() }}
  {{ DATE_RANGE_PICKER.STYLES() }}
  <link href="/static/css/page-toolbar.css" rel="stylesheet" type="text/css" />
{% endblock %}


{#----------------------------------------------------------------------------#}
{% block breadcrumb %}
  <ol class="breadcrumb">
    <li class="breadcrumb-item active" aria-current="page">Отчёт</li>
  </ol>
{% endblock %}


{#----------------------------------------------------------------------------#}
{% block content %}
  <div class="page-toolbar">
    <form id="report_form" method="post" action="/issues/report">
      {{ DATE_RANGE_PICKER.INPUT(
            from_date=from_date,
            to_date=to_date,
            id="daterange",
            name="daterange")
      }}
    </form>
  </div>

  <div class="table-container">
    {% if from_date and to_date %}
      {{ ISSUES_TABLE.TAG(columns, column_helper) }}
    {% endif %}
  </div>
{% endblock %}


{#----------------------------------------------------------------------------#}
{% block scripts %}
  {{ ISSUES_TABLE.SCRIPTS() }}
  {{ DATE_RANGE_PICKER.SCRIPTS() }}

  <script>
    document_ready_function = function() {
      {% if from_date and to_date %}
        {{ ISSUES_TABLE.DOCUMENT_READY_SCRIPT(
            columns,
            column_helper,
            url="/issues/report_data/"
              + from_date|string
              + "/"
              + to_date|string)
        }}

        {% for field, value in filter_fields.items() -%}
          filter_field('{{ field }}', '{{ value }}');
          {% if not loop.last %}
            issues_table.column('{{ field }}:name').search('{{ value }}');
          {% else %}
            issues_table.column('{{ field }}:name').search('{{ value }}').draw();
          {% endif %}
        {%- endfor %}
      {% endif %}

      {{ DATE_RANGE_PICKER.DOCUMENT_READY_SCRIPT(
            input_id="daterange",
            form_id="report_form")
      }}
    }
  </script>
{% endblock %}
